package net.mysoft.budgetsoft.system.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 拦截器基类
 * @author kangrui
 *
 */
public class BaseInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7929302758326265066L;
	
	private ActionContext actionContext;
	
	@Override
	public String intercept(ActionInvocation ai) throws Exception {
		actionContext = ai.getInvocationContext();
		return deal(ai);
	}
	
	protected String deal(ActionInvocation ai) throws Exception {
		return ai.invoke();
	}

	protected HttpServletRequest getRequest() {
		return (HttpServletRequest)actionContext.get(StrutsStatics.HTTP_REQUEST);
	}
	
	protected HttpServletResponse getResponse() {
		return (HttpServletResponse)actionContext.get(StrutsStatics.HTTP_RESPONSE);
	}
	
	protected HttpSession getSession() {
		return getRequest().getSession();
	}

}
